*merge 1:m year using "us/ANES Cumulative Data File/DS0001/08475-0001-Data.stata10.dta", nogenerate
gen VCF0004 = year
merge 1:m VCF0004 using "$sourcedatadir/us/anes_timeseries_cdf_stata12.dta", nogenerate
drop year
rename VCF0004 year

gen     income3 = .
replace income3 = 0 if VCF0114 == 1 | VCF0114 == 2
replace income3 = 1 if VCF0114 == 3
replace income3 = 2 if VCF0114 == 4 | VCF0114 == 5


gen unioninfluenced = VCF0127b
recode unioninfluenced 0=0 1=1 2=1 3=1 9=.


genl incpid=VCF0301
recode incpid 0=4
replace incpid=(((incpid-1)/3)-1)
replace incpid=-1*incpid if incumbent_dem==1

genl incvote=1 if VCF0704a==1 & incumbent_dem==1
replace incvote=1 if VCF0704a==2 & incumbent_dem==0
replace incvote=0 if VCF0704a==1 & incumbent_dem==0
replace incvote=0 if VCF0704a==2 & incumbent_dem==1

genl incpid2=incpid if VCF0301~=0


// Generate some un-incumbent-ed PID dummies
gen     pid_dem = 1 if incumbent_dem == 1 & incpid > .5
gen     pid_rep = 1 if incumbent_dem == 0 & incpid > .5
replace pid_dem = 1 if incumbent_dem == 0 & incpid < -.5
replace pid_rep = 1 if incumbent_dem == 1 & incpid < -.5
gen     pid_ind = 1 if incpid > -.5 & incpid < .5



// TH: Added 2014/04/17 as a way of trying to get at the interaction between mean-growth and top-growth at the individual level.
// This variable is an amalgam of R's retrospective ("last year") family income developments.
gen     famincretro = .
replace famincretro = 2  if VCF0881 == 1
replace famincretro = 1  if VCF0881 == 2
replace famincretro = 0  if VCF0881 == 3
replace famincretro = 2  if VCF0880 == 1
replace famincretro = 1  if VCF0880 == 2
replace famincretro = 0  if VCF0880 == 3
*replace famincretro = 2  if VCF0880B == 1 & famincretro == .
*replace famincretro = 1  if VCF0880B == 3 & famincretro == .
*replace famincretro = 0  if VCF0880B == 5 & famincretro == .
*replace famincretro = 0  if (VCF0880A == 4 | VCF0880A == 5) & famincretro == .
*replace famincretro = 2  if (VCF0880A == 1 | VCF0880A == 2) & famincretro == .
*replace famincretro = 1  if VCF0880A == 3 & famincretro == .

// Create weights that weight each election equally
*bys year: egen weight_sum = total(VCF0009)
*gen weight_eqelec = 10000*VCF0009/weight_sum 
bys year: egen weight_sum = total(vcf0009x)
gen weight_eqelec = 10000*vcf0009x/weight_sum 


// To match the variable name that we use with the other country's data sets
gen vote_ce = incvote

gen logtenure = log(incumbent_tenure)

